// @Tor Eirik Berg

//Bibliotek

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class EmailEJB
{
   public static void main(String [] args)
   {    
      // Mottakers mailadresse.
      String to = "paul.sebastian5@hotmail.com";

      // Senders mailadresse
      String from = "vipertori@msn.com";

      // sende mail fra localhost
      String host = "localhost";

      // få systemegenskaper
      Properties properties = System.getProperties();

      // sett opp mailserver
      properties.setProperty("mail.smtp.host", host);

      // session objekt.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Lager MimeMessage objekt.
         MimeMessage message = new MimeMessage(session);

         // Set Fra: header felt av header.
         message.setFrom(new InternetAddress(from));

         // Set Til: header felt av header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Sett emne: header felt
         message.setSubject("This is the Subject Line!");

         // Setter meldingen som skal sendes
         message.setText("This is actual message");

         // Send melding
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}
